<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'资源添加', styles:'bootstrap,font-awesome,animate,style,dtvalidate,layer,chosen,layui'}){%>
    <style type="text/css">
        body{padding-top:10px;}
    </style>
    <%}%>
</head>
<body>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="col-sm-offset-1 col-sm-10" style="margin-left: -10px;width: 100%;">
                <button type="button" class="return-btn btn btn-w-m btn-primary">返回</button>
                <div style="border-color: #e7eaec;border-image: none;border-style: solid solid none;border-width: 4px 0px;padding-bottom: 15px;margin-top: 10px;" ></div>
            </div>
        </div>
    </div>
</div>
<!-- START 内容部分 -->
<div class="container" >
    <form class="form-horizontal" id="info-pay_check" method="post" autocomplete="off" style="margin: auto">
        <input type="hidden" id="pay_produce_id" name="produceId" value="${produceId}">
        <div class="form-group">
            <label class="col-sm-2 control-label text-right">是否核销</label>
            <div class="col-sm-6">
                <select  id="produceIsCheck" name="produceIsCheck" class="form-control">
                    <option value="否" selected>否</option>
                    <option value="是" >是</option>
                </select>
            </div>
        </div>
        <div class="form-group check">
            <label class="control-label col-sm-2">核销金额</label>
            <div class="col-sm-6">
                <input type="text" id="produceCheckMoney" name="produceCheckMoney" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-2">付款金额</label>
            <div class="col-sm-6">
                <input type="text" id="producePayment" name="producePayment" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label text-right">杂项费</label>
            <div class="col-sm-6">
                <input type="text" id="produceUnusualMoney" name="produceUnusualMoney" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label text-right">是否收发票</label>
            <div class="col-sm-6">
                <select  id="produceIsBill" name="produceIsBill" class="form-control">
                    <option value="否" selected>否</option>
                    <option value="是" >是</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label text-right">发票凭证</label>
            <div class="col-sm-6">
                <a class="club-import-btn ">
                    <input type="file" id="importSession" name="importSession">
                </a>
                <input type="hidden" name="produceBillFile" id="produceBillFile">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label text-right">出货时间</label>
            <div class="col-sm-6">
                <input type="text" id="produceOutTime" name="produceOutTime" class="form-control">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label text-right">柜号</label>
            <div class="col-sm-6">
                <select id="createPlanNo"  class="form-control" xm-select="createPlanNo" xm-select-radio xm-select-search>
                    <option value=""></option>
                    <%for(var dict in refusedPo){%>
                    <option value="${dict.createPlanNo}">${dict.createPlanNo}</option>
                    <%}%>
                </select>

            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label text-right">备注</label>
            <div class="col-sm-6">
                <textarea id="produceReason" name="produceReason" class="remark form-control" rows="7"></textarea>
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="button" class="save-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </div>
    </form>
</div>
<!-- END 内容部分 -->

<!-- START 公共脚本 -->
<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,dtvalidate,dtvalidate-lang-zh_cn,laydate,chosen,chosen-demo,layer,layui,upload'}){}%>
<!-- END 公共脚本 -->
<script>
    laydate.render({
        elem: '#produceOutTime' //指定元素
        ,trigger: 'click'
    });
    var cvalidator;
    $(function(){
        $(".check").hide();
        $("#produceIsCheck").change(function () {
            var produceIsCheck=$("#produceIsCheck").val();
            if(produceIsCheck=='否'){
                $(".check").hide();
            }else{
                $(".check").show();
            }
        });

        //初始化验证器
        cvalidator = $.fn.dlshouwen.validator.init($('#info-form'));

        //提交表单
        $('.save-btn').on('click',function(){
            var producePayment=$("#producePayment").val();
            if(producePayment=='' || producePayment==null){
                layer.msg("预付款不能为空！",{icon:1,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            var produceIsCheck=$("#produceIsCheck").val();
            if(produceIsCheck=='是'){
                var produceCheckMoney=$("#produceCheckMoney").val();
                if(produceCheckMoney =='' || produceCheckMoney == null || produceCheckMoney==0){
                    layer.msg("核销金额不能为空或者0！",{icon:1,time:1500,shade: [0.8, '#393D49']});
                    return;
                }
            }
            layer.confirm('确定要预付款当前数据？', {
                btn: ['确定','取消'],title:'提示'
            }, function(){
                $.post('/sea/supply/produce/payment/save.do',{produceId:$("#pay_produce_id").val(),
                    producePayment:producePayment,
                    produceRemark:'付款',
                    produceIsCheck:$("#produceIsCheck").val(),
                    produceCheckMoney:$("#produceCheckMoney").val(),
                    produceUnusualMoney:$("#produceUnusualMoney").val(),
                    produceIsBill:$("#produceIsBill").val(),
                    produceBillFile:$("#produceBillFile").val(),
                    produceOutTime:$("#produceOutTime").val(),
                    createPlanNo:formSelects.value('createPlanNo', 'nameStr'),
                    produceReason:$("#produceReason").val()},function(data){
                    if( data.ok ){
                        parent.layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']});
                        parent.layer.closeAll();


                    }else{
                        layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                        layer.closeAll();
                    }

                });
            });
        });

        $("#importSession").on("change",function(){
            var formFile = new FormData($('#info-pay_check')[0]);
            var index=layer.load(1, {
                shade: [0.1,'#fff'],
                zIndex : 1111//0.1透明度的白色背景
            });
            $.ajax({
                url: "/upload/uploadFile",
                data: formFile,
                type: "post",
                processData: false,//用于对data参数进行序列化处理 这里必须false
                contentType: false, //必须
                success: function (data) {
                    console.log(data);
                    if(data.ok){
                        parent.layer.msg("上传成功！",{icon: 0,time:1500,shade: [0.8, '#393D49']});
                        $("#produceBillFile").val(data.data);
                        layer.close(index);
                    }else{
                        parent.layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                        layer.close(index);
                    }
                },
            });
        });


        layui.use('upload', function(){
            var upload = layui.upload;
            upload.render({
                elem: '#import-btn', //绑定元素,
                accept:'file',
                url: '/sea/supply/produce/payment/import/', //上传接口
                before:function () {
                    layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                }
                ,done: function(data){
                    if( data.ok ){
                        layer.msg(data.msg,{icon: 1,time: 1500},function(){
                            //刷新页面
                            $portTable.bootstrapTable('refresh');
                            layer.closeAll();
                        });
                    }else{
                        layer.msg(data.msg,{icon: 0,time: 5000},function () {
                            layer.closeAll();
                        });

                    }
                }
                ,error: function(){
                    //请求异常回调
                    layer.closeAll();
                }
            });
        });


        //返回
        $('.return-btn').on('click',function(){
            parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭弹窗
        });


    });


</script>
</body>
</html>